package com.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Slf4j
@Controller
@RequestMapping("/confirm")
public class ProducerController {

    private RabbitTemplate rabbitTemplate;

    public ProducerController(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    //发消息
    @GetMapping("/msg/{message}")
    public void sendMessage(@PathVariable("message") String message) {
        //CorrelationData correlationData = new CorrelationData("123");
        //rabbitTemplate.convertAndSend("no.confirm.exchange", "", message, correlationData);
        rabbitTemplate.convertAndSend("confirm.exchange", "key1-x", message);
        log.info("发送消息内容为{}", message);
    }

}
